package com.koron.css2.projectCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.projectCenter.bean.PjConsultBean;
import com.koron.css2.projectCenter.mapper.PjConsultMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

/**
 * 用水咨询列表-修改紧急程度
 * @author 许海宜
 * 2020年3月5日
 */
public class PjUrgentFlagUpdate implements ServerInterface {

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		try {
			//将入参转换为Bean
			List<PjConsultBean> beans = JsonUtils.jsonToList(JsonUtils.objectToJson(req.getData()), PjConsultBean.class);
			//获取Mapper实例
			PjConsultMapper mapper = factory.getMapper(PjConsultMapper.class);	
			//遍历数组
			for (PjConsultBean bean : beans) {
				//判断必填参数
				if(StringUtils.isBlank(bean.getId())||StringUtils.isBlank(bean.getUrgentFlag())){
					return MessageBean.create(Constant.NOT_NULL, "参数为空", null);
				}		
				//执行SQL
				mapper.urgentFlagUpdate(bean);
			}
			//输出结果
			return MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "修改成功", null);
		} catch (Exception e) {
			factory.close(false);
			logger.error("用水咨询修改紧急程度失败"+e.getMessage(), e);
			return MessageBean.create(Constant.MESSAGE_INT_FAIL, "修改失败", null);
		}
	}


}
